package com.itkaien.javaeebased.orginGenerics;

class GenericsClass<T> {

    private T content;
    public void setContent(T content) {
        this.content = content;
    }
    public T getContent() {
        return content;
    }
}



public class Generics {

    public static void main(String[] args) {

        GenericsClass<String> stringGenericsClass = new GenericsClass<>();
        stringGenericsClass.setContent("hello world");

        GenericsClass<Integer> integerGenericsClass = new GenericsClass<>();
        integerGenericsClass.setContent(123);

        GenericsClass genericsClass = new GenericsClass();

        //泛型 返回的就是对应的指定的泛型类型  解决了 类型向下转换 问题 泛型只能设置为 包装类

        System.out.println(integerGenericsClass.getContent());
        System.out.println(stringGenericsClass.getContent());

        System.out.println(genericsClass instanceof Object);

        test(stringGenericsClass);
        test(integerGenericsClass);
    }

    public static void test(GenericsClass<?> genericsClass ) {
        System.out.println(genericsClass.getContent());
    }


}
